<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>{:C('SERVER_NAME')}</title>
	<link rel="stylesheet" type="text/css" href="__PUBLICADMIN__/css/style.css">
</head>
<body>
	<div class="content p50">
		<div class="content-title">
			<h2>新闻套餐修改</h2>
		</div>
		<div class="p80">
			<form action="__URL__/packageForm" method="post">
			<table class="news-table">
				<tbody>
					<tr>
						<td>搜索：</td>
						<td>
							<div class="search fl"><input id="keyword"  type="text" placeholder="请输入查询关键词" ></div>
							<a href="javascript:;" class="search-btn fl"></a>
						</td>
					</tr>
					<tr>
						<td>套餐：</td>
						<td>
							<div class="package-main">
								<ul id="newsList">
									<volist name="comList" id="vo">
										<li data-id="{$vo.id}"><input type="checkbox" <if condition="in_array($vo['id'],$packageInfo['news_ids'])"> checked</if>   >({$vo.news_name}) ({$vo.news_price})</li>
									</volist>	
								</ul>
							</div>
						</td>
					</tr>
					<tr>
						<td>已选：</td>
						<td>
							<div class="package-content">
								<ul class="package-box" >
									<volist name="newsInfo" id="do">

										<li data-id="{$do.id}"><input type="checkbox" value="{$do.id}" name="news_ids[]" checked>({$do.news_name}) ({$do.news_price})</li>
									</volist>				
								</ul>
								<p>总原价：<span>{$totalPrice}</span>币 </p>
							</div>
						</td>
					</tr>
					<tr>
						<td>套餐名：</td>
						<td>
							<div class="form-text"><input type="text" name="package_name"  value="{$packageInfo.package_name}"></div>
						</td>
					</tr>
					<input type="hidden" name="id" value="{$packageInfo.id}">
					<tr>
						<td>价格：</td>
						<td>
							<div class="form-text"><input type="text" name="price" value="{$packageInfo.price}"></div>
						</td>
					</tr>	
					<tr>
						<td>是否禁用：</td>
						<td>
							<span class="form-radio">否&nbsp; <input type="radio" value="1" <if condition="$packageInfo.package_type eq '1'"> checked</if>  name="package_type"></span><span class="form-radio">是&nbsp; <input type="radio" value="0" <if condition="$packageInfo.package_type eq '0'"> checked</if> name="package_type"></span>
						</td>
					</tr>							
				</tbody>
			</table>
			<div class="form-group"><input type="submit" name="" value="提交" class="form-btn"></div>
			</form>
		</div>	

	</div>

	<script type="text/javascript" src="__PUBLIC__/js/jquery-1.7.min.js"></script>
	<script type="text/javascript" src="__PUBLICADMIN__/js/page.js"></script>
	<script type="text/javascript">

		$(document).ready(function(){


			
            var maxPage = "{$totalPages}";
            var page = 1;
            
            $(".package-main").on("scroll", function () {
            	
            	var keyword =$("#keyword").val();
            	var id ="{$packageInfo.id}";
            	var $this =$(this),
		         viewH =$(this).height(),//可见高度
		         contentH =$(this).get(0).scrollHeight,//内容高度
		         scrollTop =$(this).scrollTop();//滚动高度

            	if(scrollTop/(contentH -viewH)>=0.95){


	            	 if ( page < maxPage) {
	            	 	$.get("__URL__/newsChange", {page: page + 1,id:id,keyword:keyword}, function (data) {
	            	 	
	            	 	var str="";
	            	 	for (var i = 0; i < data.length; i++){

	            	 		str+="<li data-id='"+data[i]['id']+"' ><input type='checkbox'>("+data[i]['news_name']+") ("+data[i]['news_price']+")</li>"

	            	 	}
	            	 	str =$(str);
	            	 	$("#newsList").append(str);

	            	 	page++;	
	            	 	},"json");

	            	 }	
            	 }
            });

		});

		$(".search-btn").on("click",function(event) {

			var keyword=$("#keyword").val();
			var id ="{$packageInfo.id}";
			if(!keyword){
				window.location.reload();
			}	
				$.get("__URL__/newsChange",{keyword:keyword,id:id},function(data){
						var str="";
	            	 	for (var i = 0; i < data.length; i++){

	            	 		str+="<li data-id='"+data[i]['id']+"' ><input type='checkbox'>("+data[i]['news_name']+") ("+data[i]['news_price']+")</li>"

	            	 	}
	            	 	str =$(str);
	            	 	$("#newsList").html(str);


					
				},"json");
			
		});
		$(".package-main").on("click", ":checkbox", function () {
			var data_id=$(this).parent("li").attr("data-id");
			if ($(this).attr("checked")=="checked") {
				$(".package-box").append("<li data-id='"+data_id+"'><input type=checkbox name='news_ids[]' value='"+data_id+"' checked>"+$(this).parent().text()+"</li>")
			}else{
				$(".package-box").find("li[data-id='"+data_id+"']").remove();
			} 
			getTotolPrice();
        });
        $(".package-box").on("click",":checkbox",function () {
        	var data_id=$(this).parent("li").attr("data-id");
        	$(this).parent().remove();
        	$(".package-main").find("li[data-id='"+data_id+"'] input").attr("checked",false);
        	getTotolPrice();
        });





        function getTotolPrice(){

			var priceTotol=0;
				$(".package-box li").each(function(){

					var price=$(this).text().split('(');

						price=price[2].substring(0,price[2].length-1);	
					 priceTotol=priceTotol+parseInt(price);
				});
				$(".package-content span").text(priceTotol);
				$("input[name=order_price]").val(priceTotol);

		}
	</script>
</body>
</html>